<Window x:Class="DataBindingLab.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:src="clr-namespace:DataBindingLab" 
    Title="List of Products"
    SizeToContent="WidthAndHeight" 
    ResizeMode="NoResize"
    >
    <Window.Resources>
        <Style TargetType="{x:Type ListBoxItem}">
            <Style.Triggers>
                <Trigger Property="Selector.IsSelected" Value="True">
                    <Setter Property="Background" Value="Moccasin" />
                </Trigger>
            </Style.Triggers>
        </Style>
        <DataTemplate x:Key="groupingHeaderTemplate">
            <TextBlock Text="{Binding Path=Name}"
                       Foreground="Navy" FontWeight="Bold" FontSize="12"/>
        </DataTemplate>

        <Style x:Key="checkBoxStyle" TargetType="{x:Type CheckBox}">
            <Setter Property="Foreground" Value="#333333" />
            <Setter Property="FontWeight" Value="Bold"/>
        </Style>

        <CollectionViewSource 
              Source="{Binding Source={x:Static Application.Current}, Path=AuctionItems}"   
              x:Key="listingDataView" />
    </Window.Resources>

    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="300"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
      </Grid.RowDefinitions>

      <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
      </Grid.ColumnDefinitions>

        <TextBlock Grid.Row="0" Grid.ColumnSpan="3"
                   Style="{StaticResource titleStyle}" Margin="8,20,8,8">List of items for sale:</TextBlock>
        <CheckBox Name="Grouping" Grid.Row="1" Grid.Column="0" 
            Checked="AddGrouping" Unchecked="RemoveGrouping" 
            Margin="8" Style="{StaticResource checkBoxStyle}">Group by category</CheckBox>
        <CheckBox Name="Filtering" Grid.Row="1" Grid.Column="1" 
          Checked="AddFiltering" Unchecked="RemoveFiltering" 
          Margin="8" Style="{StaticResource checkBoxStyle}">Show only bargains</CheckBox>
        <CheckBox Name="Sorting" Grid.Row="1" Grid.Column="3" 
            Checked="AddSorting" Unchecked="RemoveSorting" 
            Margin="8" Style="{StaticResource checkBoxStyle}">Sort by category and date</CheckBox>
        <ListBox Name="Master" Grid.Row="2" Grid.ColumnSpan="3" Margin="8"
            ItemsSource="{Binding Source={StaticResource listingDataView}}">
            <ListBox.GroupStyle>
                <GroupStyle 
                  HeaderTemplate="{StaticResource groupingHeaderTemplate}"
                  />
            </ListBox.GroupStyle>
        </ListBox>

    <ContentControl Name="Detail" Grid.Row="3" Grid.ColumnSpan="3" 
            Content="{Binding Source={StaticResource listingDataView}}" 
            ContentTemplate="{StaticResource detailsProductListingTemplate}" 
            Margin="9,0,0,0"/>
        <Button Name="OpenAddProduct" Grid.Row="4" Grid.Column="1" Content="Add Product" HorizontalAlignment="Center" Margin="8" 
            Click="OpenAddProductWindow" />
    </Grid>
</Window>